#include "AVRPower.h"
#include "../../../bit/bit.h"


void setSleepEnableAVR(unsigned char flag)
{
	MCUCR = SetBit(MCUCR, 7, flag);
}


void setSleepModeAVR(unsigned char flag)
{
	switch(flag)
	{
		case IdleSleepModeAVR:
			MCUCR = SetBit(MCUCR, SM2, 0);
			MCUCR = SetBit(MCUCR, SM1, 0);
			MCUCR = SetBit(MCUCR, SM0, 0);
			break;
		case ADCNoiseReductionSleepModeAVR:
			MCUCR = SetBit(MCUCR, SM2, 0);
			MCUCR = SetBit(MCUCR, SM1, 0);
			MCUCR = SetBit(MCUCR, SM0, 1);
			break;
		case PowerDownSleepModeAVR:
			MCUCR = SetBit(MCUCR, SM2, 0);
			MCUCR = SetBit(MCUCR, SM1, 1);
			MCUCR = SetBit(MCUCR, SM0, 0);
			break;
		case PowerSaveSleepModeAVR:
			MCUCR = SetBit(MCUCR, SM2, 0);
			MCUCR = SetBit(MCUCR, SM1, 1);
			MCUCR = SetBit(MCUCR, SM0, 1);
			break;
		case ReservedSleepModeAVR:
			MCUCR = SetBit(MCUCR, SM2, 1);
			MCUCR = SetBit(MCUCR, SM1, 0);
			MCUCR = SetBit(MCUCR, SM0, 0);
			break;
		case Reserved2SleepModeAVR:
			MCUCR = SetBit(MCUCR, SM2, 1);
			MCUCR = SetBit(MCUCR, SM1, 0);
			MCUCR = SetBit(MCUCR, SM0, 1);	
			break;
		case StandbySleepModeAVR:
			MCUCR = SetBit(MCUCR, SM2, 1);
			MCUCR = SetBit(MCUCR, SM1, 1);
			MCUCR = SetBit(MCUCR, SM0, 0);
			break;
		case ExtendedStandbySleepModeAVR:
			MCUCR = SetBit(MCUCR, SM2, 1);
			MCUCR = SetBit(MCUCR, SM1, 1);
			MCUCR = SetBit(MCUCR, SM0, 1);
			break;
		default:
			MCUCR = SetBit(MCUCR, SM2, 0);
			MCUCR = SetBit(MCUCR, SM1, 0);
			MCUCR = SetBit(MCUCR, SM0, 0);
			break;
	}
}


